// 导出的 时候，是 connections.promise()  所以下面不需要写 .promise().execute()
const connection = require('../app/database')
class CommentService {
  // 创建用户
  async create(momentId, content, userId) {

    const statement = `INSERT INTO comment (content,moment_id,user_id) VALUES (?,?,?);`
    const result = await connection.execute(statement, [content, momentId, userId])
    console.log('用户注册到数据库中~');
    return result
  }
  // 回复内容
  async reply(momentId, content, userId, commentId) {

    const statement = `INSERT INTO comment (content,moment_id,user_id,comment_id) VALUES (?,?,?,?);`
    const result = await connection.execute(statement, [content, momentId, userId, commentId])

    return result
  }
  // 更新内容
  async update(commentId, content) {
    const statement = `UPDATE comment SET content = ? WHERE id = ?`;
    const [result] = await connection.execute(statement, [content, commentId]);
    return result;
  }
  // 删除内容
  async remove(commentId) {
    const statement = `DELETE FROM comment WHERE id = ?`;
    const [result] = await connection.execute(statement, [commentId]);
    return result;
  }

}
module.exports = new CommentService()